package edu.spec.sms.dao.impl;

import edu.spec.sms.dao.iface.IStudentMentalDao;
import edu.spec.sms.model.mental.StudentMental;
import org.hibernate.Query;
import org.hibernate.Session;
import org.madgecko.basic.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class StudentMentalDao extends BaseDao<StudentMental> implements IStudentMentalDao {
    @Override
    public List<StudentMental> listStudentMentalByStudent(Integer studentId) {
        // 获取没有截止的
        String hql = " from StudentMental sm where sm.student.id=" + studentId + " and sm.closeDate>:date";
        Session s = this.getSession();
        Query query = s.createQuery(hql.toString());
        query.setTimestamp("date", new Date());//注意这里，用setTimestampe，不要用setDate
        return query.list();
    }

    @Override
    public StudentMental loadByStudentAndMental(Integer studentId, Integer mentalId) {
        String hql = " from StudentMental sm where sm.student.id=" + studentId + "and sm.mental.id=" + mentalId;
        return (StudentMental) this.queryObject(hql);
    }
}
